class Notifier < ActionMailer::Base
  # a summary of many updates
  # users get this when:
  # * e-mail digests are ON
  # * the digest time interval is EXPIRED
  def digest( user )
  end

  # a notification that an assigned issue has been disowned.
  def issue_disowned( assigner, assignee, issue )
    @recipients   = assigner.email
    @cc           = assignee.email
    @from         = FLAWMILL_DISOWN_ISSUE_ACCOUNT + '@' + FLAWMILL_EMAIL_DOMAIN
    headers         "Reply-to" => 'noreply@' + FLAWMILL_EMAIL_DOMAIN
    @subject      = assignee.display + ' has disowned Issue #' + issue.local_id.to_s
    @sent_on      = Time.now
    @content_type = "text/plain"

    body[:issue] = issue
    body[:assignee] = assignee
  end

  # a notification that an assigned issue has been disowned.
  def issue_assigned( assigner, assignee, issue )
    @recipients   = assignee.email
    @from         = FLAWMILL_ASSIGN_ISSUE_ACCOUNT + '@' + FLAWMILL_EMAIL_DOMAIN
    headers         "Reply-to" => 'noreply@' + FLAWMILL_EMAIL_DOMAIN
    @subject      = assigner.display + ' has assigned Issue #' + issue.local_id.to_s + ' to you'
    @sent_on      = Time.now
    @content_type = "text/plain"

    body[:issue] = issue
    body[:assigner] = assigner
  end

  # a notification that a new issue has been posted
  # users get this when:
  # * e-mail issue notifications are ON
  # * a project that the user is a member of has a new issue posted
  # * a new issue matches a notification rule
  def new_issue( user, issue )
    @recipients   = user.email
    @from         = FLAWMILL_NEW_ISSUE_ACCOUNT + '@' + FLAWMILL_EMAIL_DOMAIN
    headers         "Reply-to" => issue.reply_to + '@' + FLAWMILL_EMAIL_DOMAIN
    @subject      = "#{issue.project.name} ##{issue.local_id}: #{issue.summary}"
    @sent_on      = Time.now
    @content_type = "text/plain"

    body[:issue] = issue
  end

  # a notification that an issue has been updated
  # users get this when:
  # * e-mail update notifications are ON
  # * an assigned/adopted issue has been updated
  #   -or-
  #   a subscribed issue has been updated
  def updated_issue( user, issue, comment )
    @recipients   = user.email
    @from         = FLAWMILL_UPDATED_ISSUE_ACCOUNT + '@' + FLAWMILL_EMAIL_DOMAIN
    headers         "Reply-to" => issue.reply_to + '@' + FLAWMILL_EMAIL_DOMAIN
    @subject      = "#{issue.project.name} ##{issue.local_id} updated: #{comment.summary}"
    @sent_on      = Time.now
    @content_type = "text/plain"

    body[:issue] = issue
    body[:comment] = comment
  end
end
